from bson.objectid import ObjectId


def objectIDtoStr(document):
    """
    单个文档Bjson objectID转换为字符串
    :param document:
    :return:
    """
    if document is None:
        return None
    document['_id'] = str(document['_id'])
    return document


def strToObjectID(strID: str):
    """
    搜索mongo数据库使用ObjectID
    示例：{'_id': strToObjectID(id)}
    :param strID:
    :return: type-->bson.objectid.ObjectId
    """
    return ObjectId(strID)


if __name__ == '__main__':
    print(type(strToObjectID("61dfd99d5b7bb6e4aa67226d")))
